# -*- coding:utf-8 -*-
# @FileName  :utils.py
# @Time      :2020/10/25 14:59
# @Author    :zhoujirong
# @Desc      :个人征信用户管理

import parameterized
import time
from common.log import Log
from biz.flow.per_credit_user import PerCreditUserRequest
from biz.cases.base_case import BaseCase
from common.params_operator import Param
from common.utils import get_redis

class TestPerCreditUser(BaseCase):
    '''个人添加征信用户'''

    data_file_name = 'credit_user.yaml'

    @classmethod
    def setUpClass(cls):
        cls.redis = get_redis()
        cls.cookie = BaseCase().get_token()

    def test_a_credist_user_create(self):
        '''添加个人征信用户'''
        creditName = self.file_data.get('creditName')
        creditUser = self.file_data.get('creditUser')
        creditOrgCode = self.file_data.get('creditOrgCode')
        creditPassword = self.file_data.get('creditPassword')
        deptCode = self.file_data.get('deptCode')
        userClass = self.file_data.get('userClass')
        digitalCertificate = self.file_data.get('digitalCertificate')
        userType = self.file_data.get('userType')
        remarks = self.file_data.get('remarks')
        userStatus = self.file_data.get('userStatus')
        ret = PerCreditUserRequest.per_create(creditName,creditUser,creditOrgCode,creditPassword,deptCode,userClass,digitalCertificate,userType,remarks,userStatus,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code, '接口调用失败')



    @parameterized.parameterized.expand(Param.from_excel('per_credit_user_data.xls'))
    def test_add_credit_user_params(self, creditName, creditUser, creditOrgCode, creditPassword, deptCode, userClass,
                                    digitalCertificate, userType, remarks, userStatus, check,desc):
        self._testMethodDoc = desc
        ret = PerCreditUserRequest.per_create(creditName,creditUser,creditOrgCode,creditPassword,deptCode,userClass,digitalCertificate,userType,remarks,userStatus,self.cookie)
        Log.info(ret)
        self.assertIn(check, ret.msg, '实际结果和预期结果不符')

    def credit_user_getpage(self):
        '''检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_creditName = self.file_data.get('search_LIKE_creditName')
        search_LIKE_creditUser = self.file_data.get('search_LIKE_creditUser')
        search_LIKE_creditOrgCode = self.file_data.get('search_LIKE_creditOrgCode')
        search_EQ_userClass = self.file_data.get('search_EQ_userClass')
        search_IN_deptCode = self.file_data.get('search_IN_deptCode')
        search_EQ_userStatus = self.file_data.get('search_EQ_userStatus')
        ret = PerCreditUserRequest.per_getpage(curPage,maxSize,search_LIKE_creditName,search_LIKE_creditUser,
                                               search_LIKE_creditOrgCode,search_EQ_userClass,search_IN_deptCode,
                                               search_EQ_userStatus,self.cookie)
        Log.info(ret)
        id_list = []
        if ret.list:
            for a in ret.list:
                id_list.append(a.id)
            Log.info(id_list)
        return id_list

    def credit_user_getpage_one(self):
        '''检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_creditName = self.file_data.get('creditName')
        search_LIKE_creditUser = self.file_data.get('creditUser')
        search_LIKE_creditOrgCode = self.file_data.get('creditOrgCode')
        search_EQ_userClass = self.file_data.get('userClass')
        search_IN_deptCode = self.file_data.get('deptCode')
        search_EQ_userStatus = self.file_data.get('userStatus')
        ret = PerCreditUserRequest.per_getpage(curPage,maxSize,search_LIKE_creditName,search_LIKE_creditUser,
                                               search_LIKE_creditOrgCode,search_EQ_userClass,search_IN_deptCode,
                                               search_EQ_userStatus,self.cookie)
        Log.info(ret)
        id_list = []
        if ret.list:
            for a in ret.list:
                id_list.append(a.id)
            Log.info(id_list)
        return id_list

    def credit_datail(self):
        '''征信用户详情'''
        id = self.credit_user_getpage_one()[0]
        ret = PerCreditUserRequest.per_detail(id,self.cookie)
        Log.info(ret)
        self.assertEqual(id,ret.id)
        return ret

    def test_b_credit_update(self):
        '''征信用户编辑'''
        createDate = self.credit_datail().createDate
        createUser = self.file_data.get('createUser')
        creditName = self.file_data.get('creditName_update')
        creditOrgCode = self.file_data.get('creditOrgCode')
        creditPassword = self.file_data.get('creditPassword_update')
        creditUser = self.credit_datail().creditUser
        deptCode = self.file_data.get('deptCode_update')
        digitalCertificate = self.file_data.get('digitalCertificate_update')
        ext1 = self.file_data.get('ext1')
        ext2 = self.file_data.get('ext2')
        ext3 = self.file_data.get('ext3')
        ext4 = self.file_data.get('ext4')
        ext5 = self.file_data.get('ext5')
        ext6 = self.file_data.get('ext6')
        id = self.credit_user_getpage_one()[0]
        initFlag = self.file_data.get('initFlag')
        isPollingGroup = self.file_data.get('isPollingGroup')
        machineCPU = self.file_data.get('machineCPU')
        machineDisk = self.file_data.get('machineDisk')
        machineNetwork = self.file_data.get('machineNetwork')
        modifyType = self.file_data.get('modifyType')
        passwordUpdateTime = self.file_data.get('passwordUpdateTime')
        pollingGroupId = self.file_data.get('pollingGroupId')
        rangeOfAction = self.file_data.get('rangeOfAction')
        resCode = self.file_data.get('resCode')
        resMsg = self.file_data.get('resMsg')
        serialNumber = self.file_data.get('serialNumber')
        updateDate = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
        updateOrg = self.file_data.get('updateOrg')
        updateUser = self.file_data.get('updateUser')
        userClass = self.file_data.get('userClass_update')
        userStatus = self.file_data.get('userStatus_update')
        userType = self.file_data.get('userType_update')
        whiteList = self.file_data.get('whiteList')
        orgTree = self.file_data.get('orgTree')
        remarks = self.file_data.get('remarks_update')
        ret = PerCreditUserRequest.per_update(createDate,
                                            createUser,
                                            creditName,
                                            creditOrgCode,
                                            creditPassword,
                                            creditUser,
                                            deptCode,
                                            digitalCertificate,
                                            ext1,
                                            ext2,
                                            ext3,
                                            ext4,
                                            ext5,
                                            ext6,
                                            id,
                                            initFlag,
                                            isPollingGroup,
                                            machineCPU,
                                            machineDisk,
                                            machineNetwork,
                                            modifyType,
                                            passwordUpdateTime,
                                            pollingGroupId,
                                            rangeOfAction,
                                            resCode,
                                            resMsg,
                                            serialNumber,
                                            updateDate,
                                            updateOrg,
                                            updateUser,
                                            userClass,
                                            userStatus,
                                            userType,
                                            whiteList,
                                            orgTree,
                                            remarks,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertIn('操作成功',ret.msg)

    def test_credit_user_del(self):
        '''删除'''
        id_list = self.credit_user_getpage()
        ret = PerCreditUserRequest.per_del(id_list,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code,'接口调用失败')



if __name__ == "__main__":
    Log.info('test')
